﻿<Window x:Class="DatavalidationSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Window.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Margin"
                    Value="4" />
            <Style.Triggers>
                <Trigger Property="Validation.HasError"
                         Value="true">
                    <Setter Property="ToolTip"
                            Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>

        </Style>
    </Window.Resources>
    <Grid>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <TextBlock Grid.Row="0"
                   Grid.Column="0"
                   Text="First name:" />
        <TextBlock Grid.Row="1"
                   Grid.Column="0"
                   Text="Last name:" />
        <TextBlock Grid.Row="2"
                   Grid.Column="0"
                   Text="Age:" />
        <TextBlock Grid.Row="3"
                   Grid.Column="0"
                   Text="Mobile No:" />

        <TextBox Grid.Row="0"
                 Grid.Column="1"
                 Text="{Binding FirstName, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
        <TextBox Grid.Row="1"
                 Grid.Column="1"
                 Text="{Binding LastName, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
        <TextBox x:Name="textbox" 
                 Grid.Row="2"
                 Grid.Column="1"
                 Text="{Binding Age, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged}" />
        <TextBox Grid.Row="3"
                 Grid.Column="1"
                 Text="{Binding MobileNo, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />
    </Grid>
</Window>

